﻿
using AiMoWindows.Entrance;

namespace AiMoWindows.Windows
{
    class ChangeLanguageViewModelBase : ViewModelBase
    {
        public RelayCommand ChangeLanguageCommand { get; }
        public ChangeLanguageViewModelBase()
        {
            ChangeLanguageCommand = new RelayCommand(SwapLanguage);
        }
        readonly HashSet<ViewModelBase> viewModels = new HashSet<ViewModelBase>();
        public void AppendLanguageChangeModel(ViewModelBase viewModel)
        {
            viewModels.Add(viewModel);
        }
        public void UpdateAllUIWindows()
        {
            RaisePropertyChanged();
            foreach (var model in viewModels) model.RaisePropertyChanged();
        }
        void SwapLanguage()
        {
            Localization.Local.SwapLanguage();
            AiMoProgram.Instance.UpdateAllWindowState();
            OnLanguageChanged?.Invoke(this, EventArgs.Empty);
        }
        public event EventHandler? OnLanguageChanged;
        public string LanguageButtonText => IsEnglish ? "EN" : "CN";
        protected bool IsEnglish => !Localization.Local.RunningInChinese;
    }
}
